package com.itheima;

import com.itheima.dao.GoodsDao;
import com.itheima.pojo.Goods;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class Demo03CustomMethodQuery {

    @Autowired
    private GoodsDao goodsDao;


    /**
     * 根据标题及价格查询
     * 要求价格等于20023且标题的内容包含小米关键词
     */
    @Test
    public void findAllByTitleAndPrice() {
        String title = "小米";
        Double price = 20023.0;
        List<Goods> goods = goodsDao.findAllByTitleAndPrice(title, price);
        for (Goods g : goods) {
            System.out.println(g);
        }
    }

    /**
     * 根据价格范围查询
     * 要求商品价格再3000，到20000之间
     */
    @Test
    public void findPriceBetween(){
        double lowPrice = 3000.0;//最低价
        double highPrice = 20000.0;//最高价
        List<Goods> goods = goodsDao.findByPriceBetween(lowPrice, highPrice);
        for (Goods g : goods) {
            System.out.println(g);
        }
    }
}






















